package xyz.sicau.blog.dao;

import org.apache.ibatis.annotations.Select;
import xyz.sicau.blog.bean.Blog;

import java.util.List;
import java.util.Map;

public interface BlogMapper {
    // 查询全部博客
    @Select("select * from blog")
    List<Blog> getBlogAll();

    /**
     * 分页查询
     * @param start 从第条记录开始
     * @param page 查询多少条记录
     */
    @Select("select * from blog order by blog_time desc limit #{start} , #{page}")
    List<Blog> getBlogPage(int start, int page);

    /**
     * 插入博客
     */
    int insertBlog(Blog blog);


    /**
     * 通过blogId查博客
     */
    @Select("select * from blog where blog_id=#{blogId}")
    Blog getBlogById(int blogId);

    /**
     * 查询博客分类的条数
     */
    @Select("select blog.blog_label, count(*) as count from blog group by blog.blog_label")
    List<Map<String, Integer>> getBlogCount();

    /**
     * 通过用户查博客
     */
    @Select("select * from blog where blog_username=#{blogUserName}")
    List<Blog> getBlogsByUsername(String blogUserName);
    @Select("select * from blog where blog_userid=#{blogUserId}")
    List<Blog> getBlogsByUserid(int blogUserId);
    // 分页查
    @Select("select * from blog where blog_username=#{blogUserName} order by blog_time desc limit #{start} , #{page}")
    List<Blog> getBlogsPageByUsername(String blogUserName, int start, int page);
    @Select("select * from blog where blog_userid=#{blogUserId} order by blog_time desc limit #{start} , #{page}")
    List<Blog> getBlogsPageByUserid(int blogUserId, int start, int page);
}
